<?php
   // $Id: bulkrestore.php, v 1.0.0.0 2008/07/17 deanthayer Exp $
   // Front end form for restorebulk.php
   
   //Units used
    require_once("../config.php");
    require_once("../lib/xmlize.php");
    require_once("../lib/datalib.php");
    require_once("../course/lib.php");
    require_once("lib.php");
    require_once("restorelib.php");
    require_once("bb/restore_bb.php");
    require_once("$CFG->libdir/blocklib.php");
    require_once("$CFG->libdir/wiki_to_markdown.php" );
    require_once("$CFG->libdir/adminlib.php");

    //Print header
    if (has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
        print_header("Bulk Course Restore", 'Bulk Course Restore',
                      "Bulk Course Restore -> Choose Source Course and Destination Categories");
    } 

 
?>
<script type="text/javascript">
<!--
function selectItemInMenuByName(formId, menuName, selectIndex ) {
    myForm = document.getElementById(formId)
    for (i=0,n=myForm.elements.length;i<n;i++) {
        myLen = menuName.length;
        myName = myForm.elements[i].name;
        myType = myForm.elements[i].type;
        if (myName.substring(0,myLen) == menuName && myType == "select-one") {
            myForm.elements[i].options[selectIndex].selected = true;
        }
    }
}

function selectItemInRadioByName(formId, radioName, selectIndex ) {
    myForm = document.getElementById(formId)
    for (i=0,n=myForm.elements.length;i<n;i++) {
        myLen = radioName.length;
        myName = myForm.elements[i].name;
        myType = myForm.elements[i].type;
        if (myName.substring(0,myLen) == radioName && myType == "radio") {
            myRadioGroup = myForm.elements[myName];
            myRadioGroup[selectIndex].checked = true;
        }
    }
}

function selectItemInCheckboxByName(formId, checkName, checked ) {
    myForm = document.getElementById(formId)
    for (i=0,n=myForm.elements.length;i<n;i++) {
        myLen = checkName.length;
        myName = myForm.elements[i].name;
        myType = myForm.elements[i].type;
        if (myName.substring(0,myLen) == checkName && myType == "checkbox") {
            myForm.elements[i].checked = checked;
        }
    }
}
-->
</script>

<form id="form1" method="post" action="restorebulk.php">
<div>
<table cellpadding="5" class="boxaligncenter">
<?php
    if (user_can_create_courses()) {  //display these fields conditionally
        // find the list of courses user can see
        echo "<tr valign=\"top\" >";
        echo "<td align=\"right\">";
        echo "Source ";
	print_string('course');
        echo " :</td>";
        echo "<td>";
	$allcourses = array();
        $courses = get_courses("all", "c.fullname ASC", "c.id,c.fullname");
        foreach ( array_keys($courses) as $key ) {
		$course = get_object_vars($courses[$key]);
		foreach ( array_keys($course) as $coursekey) {
			if ($coursekey == 'id') {
				$allcourses[$course['id']] = $course['fullname'];
			}
		}
	}
        choose_from_menu($allcourses, "id");        
        echo "</td>";
        echo "</tr>";
        // find the list of categories user can edit
        echo "<tr valign=\"top\" >";
        echo "<td align=\"right\">";
        echo "Destination ";
	print_string('category');
        echo " :</td>";
        echo "<td>";
        choose_from_menu(get_creatable_categories(), "termcat");        
        echo "</td>";
        echo "</tr>";
    }
?>
</table>
<br />
<div style="text-align:center">
<input type="submit" value="<?php  print_string("continue") ?>" />
<input type="submit" name="cancel" value="<?php  print_string("cancel") ?>" />
</div>
</div>
</form>

<?php
print_footer();
?>
